<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>新增轮播图</title>
    <script src="../../js/jquery.min.js"></script>
    <script src="../../js/common.js"></script>
    <script src="../../js/jquery.cookie.js"></script>
    <script src="../../js/layer/layer.js"></script>
    <style type="text/css">
        ul li {
            list-style: none;
            display: inline-block;
        }
    </style>
</head>
<body>
<div>
    <ul>
        <li>图片:
            <form id="uploadForm" enctype="multipart/form-data">
                文件:<input id="file" type="file" name="file"/>
            </form>
        </li>
        <li>描述:<input type="text" id="desc" name="desc"/></li>
        <li><input type="button" value="提交" id="btn"/></li>
    </ul>
</div>
</body>
<script>
    $(function () {
        $("#btn").click(function () {
            submit();
        });
    });
    function submit() {

        var formData = new FormData($('#uploadForm')[0]);
        console.log(formData.get("file"))
        if (formData ==={} || formData===""){
            alert("请选择文件")
        }
        formData.append("file",formData.get("file"));
        //调用formData的append方法，将book属性都添加进去，img填空白即可。
        formData.append("name",$("#name").val());
        formData.append("desc",$("#desc").val());


        $.ajax({
            type: 'post',
            url: baseUrl+"index/new.json",
            data: formData,
            cache: false,
            processData: false,
            contentType: false,
            success: function (data) {
                if (data.code == "200") {
                    window.location.href = baseUrl+"back/index/list.html";
                } else {
                    layer.msg("修改失败!",{icon:5});
                }
            },
            error:(function () {
                alert("上传失败");
            }),
        });
    }

</script>
</html>